//package com.xy.stock.config;
//
//
//import com.xy.stock.service.UserService;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.context.annotation.Bean;
//import org.springframework.context.annotation.Configuration;
//import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
//import org.springframework.security.config.annotation.web.builders.HttpSecurity;
//import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
//import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
//import org.springframework.security.core.userdetails.User;
//import org.springframework.security.core.userdetails.UserDetails;
//import org.springframework.security.core.userdetails.UserDetailsService;
//import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
//import org.springframework.security.crypto.factory.PasswordEncoderFactories;
//import org.springframework.security.crypto.password.DelegatingPasswordEncoder;
//import org.springframework.security.crypto.password.NoOpPasswordEncoder;
//import org.springframework.security.crypto.password.PasswordEncoder;
//import org.springframework.security.provisioning.InMemoryUserDetailsManager;
//import org.springframework.security.web.SecurityFilterChain;
//
////@Configuration
////@EnableWebSecurity
//public class ScurityConfig {
//
//    //添加密码加密方法，由于Spring Security5必须要对密码进行编码，而Spring Security4不需要
//    @Bean
//    public PasswordEncoder passwordEncoder(){
//        return new BCryptPasswordEncoder();
//    }
//
//    //处理 前后端分离页面 哪个接口执行登录 并对成功和失败分别给出回应
//    public SecurityFilterChain securityFilterChain(HttpSecurity httpSecurity) throws Exception{
//        //successHandler 登陆成功处理逻辑 只要实现接口：AuthenticationSuccessHandler
//        //failureHandler 登陆失败处理逻辑 只要实现接口：AuthenticationFailureHandler
//        //httpSecurity.formLogin().loginProcessingUrl("/login").successHandler(。。。).failureHandler(。。。);
//
//        //异常的处理
//        httpSecurity.csrf().disable();
//        httpSecurity.exceptionHandling((exceptionHandlingConfigurer)->{
//
//            //exceptionHandlingConfigurer.authenticationEntryPoint(); //认证异常捕获 实现AuthenticationEntryPoint
//            //exceptionHandlingConfigurer.accessDeniedHandler();   //授权异常捕获 实现AccessDeniedHandler
//        });
//        return httpSecurity.build();
//    }
//
//    //第二种方式
//   /*@Bean
//   public static NoOpPasswordEncoder passwordEncoder() {
//      return (NoOpPasswordEncoder) NoOpPasswordEncoder.getInstance();
//   }*/
//
////    @Bean
////    public UserDetailsService userDetailsService() {
////        UserDetails user = User.withUsername("admin").password(passwordEncoder().encode("123456")).roles("user","admin").build();
////        return new InMemoryUserDetailsManager(user);
////    }
//}
